<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$userid=$this->checklogin();
$return=array();
if($_RQ['id']){
	$_SESSION['hotelid']=$_RQ['id'];
}
$hotelid=$_SESSION['hotelid'];

if($_RQ['op']=='list'){
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$params=array('uniacid'=>$_SESSION['uniacid'],'hotelid'=>$hotelid);
    $fields=array('id','title','image','num');
    $orderby='id desc';
	$total='';
	$return['list']=pdo_getslice('jy_jd_room',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'房型管理'),
			array('op'=>'edit','title'=>'添加房型'),
		),
		'list'=>array('data'=>'list','list'=>array(
			'1'=>array('name'=>'title','title'=>'名称','type'=>'string'),
			'2'=>array('name'=>'image','title'=>'图片','type'=>'image'),
			'3'=>array('name'=>'num','title'=>'数量','type'=>'string'),
			
		),'action'=>array(
			array('type'=>'href','action'=>'/manage.price_pai/','title'=>'房间定价/数量'),
		)),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
	$item=pdo_get('jy_jd_room',array('id'=>$id));
	
	}else{
		$item=array();
	}
	if($item['images']){
		$item['images']=json_decode($item['images'],true);
	}else{
		$item['images']=array();
	}
	$item['taocan']=json_decode($item['taocan'],true);
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'房型设置',
		'tabs'=>array(
			array('op'=>'list','title'=>'房型设置'),
			array('op'=>'edit','title'=>'添加房型')
		),
		'edit'=>array(
			array('name'=>'title','title'=>'名称','type'=>'string'),
			array('name'=>'image','title'=>'图片','type'=>'image'),
			array('name'=>'images','title'=>'多图','type'=>'images'),
			//array('name'=>'price','title'=>'市场价格','type'=>'string'),
			//array('name'=>'mprice','title'=>'会员价格','type'=>'string'),
			array('name'=>'service','title'=>'服务费','type'=>'string'),
			array('name'=>'iprice','title'=>'押金','type'=>'string'),
			array('name'=>'breakfast','title'=>'是否含早餐','type'=>'radio','options'=>'breakfast'),
			array('name'=>'is_opentui','title'=>'支持退订','type'=>'switch'),
			array('name'=>'tui_day','title'=>'入驻N天前','type'=>'unitstring','unit'=>'天','show'=>array('is_opentui'=>1)),
			array('name'=>'tui_time','title'=>'退订时间点前','type'=>'time_onehour','show'=>array('is_opentui'=>1)),
			array('name'=>'tui_fee','title'=>'退订手续费','type'=>'unitstring','unit'=>'元','show'=>array('is_opentui'=>1)),
			array('type'=>'array',
				'name'=>'taocan',
				'title'=>'房套餐管理',
				'add_tip'=>'添加一个房套餐',
				'list'=>array(
					array('type'=>'string','name'=>'title','title'=>'房套餐名称'),	
					array('type'=>'string','name'=>'price','title'=>'房套餐价格'),	
				),
				'details'=>array(
					array('type'=>'string','name'=>'title','title'=>'房套餐名称'),	
					array('type'=>'string','name'=>'price','title'=>'房套餐价格'),	
				)
			),		
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'louceng','title'=>'楼层','type'=>'string'),
			array('name'=>'chuang','title'=>'床大小(米)','type'=>'string'),
			array('name'=>'mianji','title'=>'面积','type'=>'string'),
			array('name'=>'num','title'=>'房间数量','type'=>'string'),
			)
		);
	$return['status']=array('0'=>'关闭','1'=>'开启');
	$return['breakfast']=array('1'=>'含','0'=>'不含');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array_fields(array('is_opentui','tui_day','title','image','images','tui_fee','tui_time','taocan','chuang','tprice','price','mprice','service','iprice','breakfast','status','num','louceng','mianji'),$postdata);
	$data['taocan']=json_encode($data['taocan']);
	$data['images']=json_encode($data['images']);
	if(!$data['taocan']){
		exi('请先添加套餐','error');
	}
	$id=intval($postdata['id']);
			if($id){
				pdo_update('jy_jd_room',$data,array('id'=>$id));
				exi('设置成功！','','/manage.hotel/');
			}else{
				$data['hotelid']=$_SESSION['hotelid'];
			    $data['uniacid']=$_SESSION['uniacid'];
				pdo_insert('jy_jd_room',$data);
				exi('添加成功！','','/manage.hotel/');
			}
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('jy_jd_room',array('id'=>$id));	
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('jy_jd_room',array('id'=>$id));
			}
		}
	}
	exi('删除成功！');
}
?>